找传奇、传世资源到传世资源站!
SQL/SQL基础 正文

保存数据库中所有外键信息

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

将现在数据库中所有外键信息保存

--用游标将所有外键去除
declare cursor_detail cursor
for select tabname , fkid , fkname , rtabname , fcolname , rcolname from keytab where keyno = 1
open cursor_detail
fetch next from cursor_detail into @s_tabname , @s_fkid , @s_fkname , @s_rtabname , @s_fcolname , @s_rcolname
while @@fetch_status = 0
begin
if exists(select [id] from sysobjects where id = cast(@s_fkid as int) and xtype = 'F')
begin
select @s_sql = 'ALTER TABLE ' @s_tabname ' DROP CONSTRAINT ' @s_fkname
exec (@s_sql)
end
if @@error <> 0 
begin
close cursor_detail
deallocate cursor_detail
raiserror('删除数据游标出错',16,1)
return -1
end
fetch next from cursor_detail into @s_tabname , @s_fkid , @s_fkname , @s_rtabname , @s_fcolname , @s_rcolname
end
close cursor_detail
deallocate cursor_detail

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复